﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ViewAlbumUserControl.ascx.cs"
    Inherits="JM.JCY.SharePointComponent.PhotoAlbum.ViewAlbum.ViewAlbumUserControl" %>
<link href="/_layouts/JM.JCY.Resource/styles/JCYStyle.css" rel="stylesheet" type="text/css" />
<style type="text/css">
    #imagebox
    {
        border: 1px solid #B8B8B8;
        background-color: #ffffff;
        padding: 4px;
        border-bottom: 1px solid #B8B8B8;
    }
    
    .editcss, .commoncss
    {
        padding: 3px 0 0 10px;
        float: right;
    }
</style>
<script type="text/javascript">

    var belongto = null;
    var currentgroup = null;
    var enable = null;
    var albumurl = null;
    var wcfnewsfeedUrl = newsfeedSvcUrl;
    var wcfUrl = PhotoAlbumUrl;

    $(document).ready(function () {

        var AlbumId = $("#<%=HiddenAlbumId.ClientID %>").val();
        var lastUpdatedTime = $("#<%=HiddenLastUpdatedTime.ClientID %>").val();

        $("#timeagoSpan").text($.timeago(lastUpdatedTime));

        var lbBackHome = $("#<%=lbBackHome.ClientID %>");
        lbBackHome.live('click', function () {
            Goback();
            return false;
        });

        var lbBackHome2 = $("#<%=lbBackHome2.ClientID %>");
        lbBackHome2.live('click', function () {
            Goback();
            return false;
        });

        var lbAddMoreMedia = $("#<%=lbAddMoreMedia.ClientID %>");
        lbAddMoreMedia.live('click', function () {
            location.href = "AddMoreMedia.aspx?AlbumId=" + AlbumId;
            return false;
        });

        var lbEditThisAlbum = $("#<%=lbEditThisAlbum.ClientID %>");
        lbEditThisAlbum.live('click', function () {
            location.href = "EditAlbum.aspx?AlbumId=" + AlbumId;
            return false;
        });

        var lbRemoveThisAlbum = $("#<%=lbRemoveThisAlbum.ClientID %>");
        lbRemoveThisAlbum.live('click', function () {
            showConfirm('', "你真的要删除这个相册吗？", RemoveAlbumDoCall, CancelCall, null);
            return false;
        });
        checkCanBeEdited();
        // pagings
        SetCurrentLink(1);

        Showpagination();
    });

    function Goback() {
        var apptype = $("#<%=HiddenFieldAppType.ClientID %>").val();
        var appid = $("#<%=HiddenFieldAppId.ClientID %>").val();
        location.href = "ViewAllAlbums.aspx?Type=" + apptype + "&appid=" + appid;   
    }

    function AddMoreMediaYesCall() {
        var AlbumId = $("#<%=HiddenAlbumId.ClientID %>").val();
        location.href = albumurl + "/AddMoreMedia.aspx?AlbumId=" + AlbumId;
    }

    function EditAlbumYesCall() {
        var AlbumId = $("#<%=HiddenAlbumId.ClientID %>").val();
        location.href = albumurl + "/EditAlbum.aspx?AlbumId=" + AlbumId;
    }

    function RemoveAlbumYesCall() {
        var AlbumId = $("#<%=HiddenAlbumId.ClientID %>").val();
        location.href = albumurl + "/ViewAlbum.aspx?AlbumId=" + AlbumId;
    }

    function RemoveAlbumDoCall() {
        __doPostBack("removeAlbum");
    }
    function CancelCall() {
        //Do Nothing.
    }

    function checkCanBeEdited() {
        enable = $("#<%=HiddenFieldEableEdit.ClientID %>").val();
        albumurl = $("#<%=HiddenFieldAlbumUrl.ClientID %>").val();
        if (enable == "T") {
            $("#divedit").css("display", "block");
        } else {
            $("#divedit").css("display", "none");
        }
    }
    function turnPage(pageIndex) {
        $("#currIndex").val(pageIndex);
        SetCurrentLink(pageIndex);
        CallServer(pageIndex, 'content');
    }

    function turnPagePrev() {

        var prevIndex = parseInt($("#currIndex").val());
        var currentIndex = 1;
        if (prevIndex > 1)
            currentIndex = prevIndex - 1;
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function turnPageNext() {

        var prevIndex = parseInt($("#currIndex").val());
        var currentIndex = $("#lastIndex").val();
        if (prevIndex < $("#lastIndex").val())
            currentIndex = prevIndex + 1;
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function turnPageLast() {

        var currentIndex = $("#lastIndex").val();
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function ReceiveCallback(arg, context) {
        var container = document.getElementById(context);
        container.innerHTML = arg;
    }

    function SetCurrentLink(currentIndex) {

        var lastIndex = $("#lastIndex").val();
        var i;
        for (i = 1; i <= lastIndex; i++) {
            if (i == currentIndex)
                $("#a" + i).css('text-decoration', 'underline');
            else
                $("#a" + i).css('text-decoration', 'none');
        }

        //Set First,Previous,Next, Last button enable or disable
        if (currentIndex == 1) {
            $("#lbFirst").attr("disabled", "true");
            $("#lbPrev").attr("disabled", "true");
        }
        else {
            $("#lbFirst").removeAttr("disabled");
            $("#lbPrev").removeAttr("disabled");
        }

        if (currentIndex == lastIndex) {
            $("#lbNext").attr("disabled", "true");
            $("#lbLast").attr("disabled", "true");
        }
        else {
            $("#lbNext").removeAttr("disabled");
            $("#lbLast").removeAttr("disabled");
        }
    }

    function copyclick() {
        clipboardData.setData('text', window.location.href)
    }

    function getSharepointObjectId() {

        var sharepointObjectId = $("#<%=HiddenObjectId.ClientID %>").val();
        return sharepointObjectId;
    }

    function getMediaID() {
        return 0;
    }

    function getCurrentUrl() {
        return "a|b";
    }

    function getStaffId() {
        var staffId = $("#<%=HiddenStaffId.ClientID %>").val();
        return staffId;
    }

    function getApplicationId() {
        var ApplicationId = $("#<%=HiddenAppId.ClientID %>").val();
        return ApplicationId;

    }

    function redirectComment() {
        var txtComment = $("#txtComment");
        txtComment.focus();

    }

    function clickLike(spobjectId, btnlikeId, lbllikenumId) {

        var staffId = $("#<%=HiddenStaffId.ClientID %>").val();

        var objectId = getSharepointObjectId();
        var staffId = $("#<%=HiddenStaffId.ClientID %>").val();
        var objectType = "pic";
        $.ajax({
            type: "Get",
            url: wcfUrl + "LikeOfAlbum?staffId=" + staffId + "&objectId=" + spobjectId + "&objectType=" + objectType,
            contentType: "application/json; charset=utf-8",
            dataType: 'jsonp',
            success: function (result) {
                getLikes(spobjectId, btnlikeId, lbllikenumId, staffId);
            },
            error: function (a, b, c) { alert(c); },
            failure: function (msg) {
                alert(msg);
            }
        });

        return false;
    }

    function getLikes(spobjectId, btnlikeId, lbllikenumId, staffId) {
        var objectType = 'pic';
        $.ajax({
            type: "Get",
            url: wcfUrl + "GetLikes?staffId=" + staffId + "&objectId=" + spobjectId + "&objectType=" + objectType,
            contentType: "application/json; charset=utf-8",
            dataType: 'jsonp',
            success: function (result) {
                if (result == "[]") {
                    showLikeNum(lbllikenumId, 0);
                    showLikeTitle(btnlikeId, "Like");
                } else {
                    var JSON = eval('(' + (result) + ')');
                    showLikeNum(lbllikenumId, JSON[0].count);
                    if (JSON[0].staffId == getStaffId()) {
                        showLikeTitle(btnlikeId, "一般");
                    } else {
                        showLikeTitle(btnlikeId, "喜欢");
                    }
                }
            },
            error: function (a, b, c) { alert(c); },
            failure: function (msg) {
                alert(msg);
            }
        });
    }

    function showLikeNum(objId, likenum) {
        $("span[id='" + objId + "']").text(likenum);
    }
    function showLikeTitle(objId, likeTitle) {
        $("a[id='" + objId + "']").text(likeTitle);
    }

    function Showpagination() {
        var pageNum = $("#<%=HiddenFieldPageNum.ClientID %>").val();
        if (pageNum == 1) {
            $("div.pagination").css("display", "none");
            $("#backToAlbum").css("display", "block");
            $("#backToAlbum").addClass("pagination");
        }
    }
</script>
<div class="gallery">
    <table width="100%" class="galleryTitle">
        <tr>
            <td>
                <h2 class="gallery">
                    <img src="/_layouts/JM.JCY.Resource/images/相册小.png" width="24">
                    查看相册</h2>
            </td>
            <td align="right" class="link">
                <div id="divcom" class="editcss">
                 <img src="/_layouts/JM.JCY.Resource/images/movie_file.png" width="12">
                    <asp:LinkButton ID="lbViewSlideShow" CssClass="galleryDetail" runat="server">幻灯片浏览</asp:LinkButton>
                        </div>
                <div id="divedit" class="editcss">
                <img src="/_layouts/JM.JCY.Resource/images/plus.png" width="12"/>
                    <asp:LinkButton ID="lbAddMoreMedia" CssClass="galleryDetail" runat="server">添加照片</asp:LinkButton>
                    | <img src="/_layouts/JM.JCY.Resource/images/EDIT.gif" width="12"/>
                    <asp:LinkButton ID="lbEditThisAlbum" CssClass="galleryDetail" runat="server">编辑相册</asp:LinkButton>
                    |
                     <img src="/_layouts/JM.JCY.Resource/images/delete.png" width="12"/>
                    <asp:LinkButton ID="lbRemoveThisAlbum" CssClass="galleryDetail" runat="server" OnClick="lbRemoveThisAlbum_Click">删除相册</asp:LinkButton>
                    |</div>
            </td>
        </tr>
        <tr>
        <td colspan=2>
        <br />
        <hr />
        </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:Label ID="lblAlbumName" CssClass="gallery" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <h2 class="galleryDetail">
                    <asp:Label ID="lblCreater" runat="server"></asp:Label></h2>
            </td>
            <td align="right">
                <div id="backToAlbum" style="display: none">
                <img src="/_layouts/JM.JCY.Resource/images/back_Link.png" width="12"/>
                    <asp:LinkButton ID="lbBackHome2" runat="server" CssClass="link" Font-Size="12px">返回相册集</asp:LinkButton>
                </div>
                <div class="pagination">
                    <img src="/_layouts/JM.JCY.Resource/images/back_Link.png" width="12"/>
                    <asp:LinkButton ID="lbBackHome" runat="server" CssClass="link" Font-Size="12px" 
                        >返回相册集</asp:LinkButton>
                    &nbsp;&nbsp;
                    <asp:LinkButton ID="lbFirst" runat="server" Text="<< 第一页" class="galleryDetailOfpagination"
                        OnClientClick="turnPage(1);return false;"></asp:LinkButton>
                    <asp:Label ID="lbl2" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbPrev" runat="server" Text="< 上一页" class="galleryDetailOfpagination"
                        OnClientClick='turnPagePrev();return false;'></asp:LinkButton>
                    <asp:Label ID="lbl4" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbNext" runat="server" Text="下一页 >" class="galleryDetailOfpagination"
                        OnClientClick='turnPageNext();return false;'></asp:LinkButton>
                    <asp:Label ID="lbl5" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbLast" runat="server" Text="最后一页 >>" class="galleryDetailOfpagination"
                        OnClientClick='turnPageLast();return false;'></asp:LinkButton>
                    <input id="currIndex" type="text" value="1" style="display: none;" />
                    <input id="lastIndex" type="text" value="<%=lastIndex%>" style="display: none;" />
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="width:98%; text-align:center">
                <div id="content">
                    <asp:DataList ID="DatalistViewAlbum" runat="server" RepeatColumns="5" CellPadding="4"
                        OnItemDataBound="DatalistViewAlbum_OnItemDataBound" CellSpacing="2" DataKeyField="AlbumContentId"
                        RepeatDirection="Horizontal">
                        <ItemTemplate>
                            <div>
                                <table>
                                    <tr>
                                        <td>
                                            <div class="ThumbNailImg">
                                                <div id="imagebox">
                                                    <asp:Literal ID="LiteralViewMedia" runat="server"></asp:Literal>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr id="Tr1" runat="server">
                                        <td>
                                            <div class="ThumbNailImg">
                                                <asp:Image ID="imgLike" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/thumbs-up.gif" />
                                                <asp:Label ID="lblLikeCount" CssClass="gallery" runat="server" Text="10"></asp:Label>
                                                <asp:LinkButton ID="lkbLike" runat="server" Text="Like" CssClass="galleryDetail"></asp:LinkButton>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </ItemTemplate>
                    </asp:DataList>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <table width="100%" class="thumbnail">
                    <tr>
                        <td class="albumdesc">
                            <asp:Label ID="lblAlbumDesc" CssClass="gallery" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h2 class="galleryDetail">
                                <span id="timeagoSpan"></span>&nbsp;|&nbsp;<a class="galleryDetail" href="javascript:redirectComment();">添加评论</a>
                            </h2>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <div class="pagination">
                                <asp:LinkButton ID="lbFirstDown" runat="server" Text="<< 第一页" class="galleryDetailOfpagination"
                                    OnClientClick="turnPage(1);return false;"></asp:LinkButton>
                                <asp:Label ID="Label1" runat="server" Text="|"></asp:Label>
                                <asp:LinkButton ID="lbPrevDown" runat="server" Text="< 上一页" class="galleryDetailOfpagination"
                                    OnClientClick='turnPagePrev();return false;'></asp:LinkButton>
                                <asp:Label ID="Label2" runat="server" Text="|"></asp:Label>
                                <asp:LinkButton ID="lbNextDown" runat="server" Text="下一页 >" class="galleryDetailOfpagination"
                                    OnClientClick='turnPageNext();return false;'></asp:LinkButton>
                                <asp:Label ID="Label3" runat="server" Text="|"></asp:Label>
                                <asp:LinkButton ID="lbLastDown" runat="server" Text="最后一页 >>" class="galleryDetailOfpagination"
                                    OnClientClick='turnPageLast();return false;'></asp:LinkButton>
                                <input id="currIndexDown" type="text" value="1" style="display: none;" />
                                <input id="lastIndexDown" type="text" value="<%=lastIndex%>" style="display: none;" />
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
<asp:HiddenField ID="HiddenFieldViewAlbumUrl" runat="server" />
<asp:HiddenField ID="HiddenAlbumId" runat="server" />
<asp:HiddenField ID="HiddenObjectId" runat="server" />
<asp:HiddenField ID="HiddenStaffId" runat="server" />
<asp:HiddenField ID="HiddenFieldEableEdit" runat="server" />
<asp:HiddenField ID="HiddenAppId" runat="server" />
<asp:HiddenField ID="HiddenLastUpdatedTime" runat="server" />
<asp:HiddenField ID="HiddenFieldAlbumUrl" runat="server" />
<asp:HiddenField ID="HiddenFieldRemoveAblum" runat="server" />
<asp:HiddenField ID="HiddenFieldPageNum" runat="server" />
<asp:HiddenField ID="HiddenFieldAppType" runat="server" />
<asp:HiddenField ID="HiddenFieldAppId" runat="server" />
